package com.example.reone.mydatapicker;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by wangxingsheng on 2016/10/17.
 */

public class DataPickerItemView extends LinearLayout implements View.OnClickListener {
    private View _upBtn,_bottomBtn;
    private TextView _middleTv;
    private OnDataPickerItemChangeListener _OnDataPickerItemChangeListener;
    public DataPickerItemView(Context context) {
        super(context);
        initView();
    }

    public DataPickerItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public DataPickerItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }
    private void initView(){
        LayoutInflater.from(getContext()).inflate(R.layout.layout_data_picker_item_view, this,true);
        _upBtn = findViewById(R.id.data_picker_item_top_btn);
        _bottomBtn = findViewById(R.id.data_picker_item_bottom_btn);
        _middleTv = (TextView) findViewById(R.id.data_picker_item_middle_text);
        _upBtn.setOnClickListener(this);
        _bottomBtn.setOnClickListener(this);
    }
    public void setText(Object number){
        _middleTv.setText(number.toString());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.data_picker_item_top_btn:
                if(_OnDataPickerItemChangeListener!=null)
                    _OnDataPickerItemChangeListener.onItemUpPress(this);
                break;
            case R.id.data_picker_item_bottom_btn:
                if(_OnDataPickerItemChangeListener!=null)
                    _OnDataPickerItemChangeListener.onItemBottomPress(this);
                break;
            default:
        }
    }

    public void setOnDataPickerItemChangeListener(OnDataPickerItemChangeListener onDataPickerItemChangeListener){
        _OnDataPickerItemChangeListener = onDataPickerItemChangeListener;
    }

    public interface OnDataPickerItemChangeListener{
        void onItemUpPress(View v);
        void onItemBottomPress(View v);
    }
}
